<template>
  <div>
    <h1>管理员账户展示</h1>
    <el-table :data="item">
      <el-table-column prop="_id" label="ID" width="230"> </el-table-column>
      <el-table-column prop="username" label="用户名"> </el-table-column>
      <el-table-column fixed="right" label="操作" width="180">
        <template slot-scope="scope">
          <el-button
            @click="$router.push(`/adminusers/edit/${scope.row._id}`)"
            size="small"
            >编辑</el-button
          >
          <el-button @click="remove(scope.row)" size="small">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  name: "AdminUsersList",

  data() {
    return {
      item: [],
    };
  },
  methods: {
    async fetch() {
      const res = await this.$http1.get("rest/adminusers");
      this.item = res.data;
    },
    async remove(row) {
      this.$confirm(`此操作将永久删除分类 ${row.name}, 是否继续?`, "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          const res = await this.$http1.delete(`rest/adminusers/${row._id}`);
          this.$message({
            type: "success",
            message: "删除成功!",
          });
          this.fetch();
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
  },
  created() {
    this.fetch();
  },
};
</script>

<style>
</style>